<?session_start();?>
<?php require_once 'xhtmlHeader.php';?>

<script type="text/javascript" src="lib/jquery.min.js"></script> 
<script type="text/javascript" src="lib/jquery.pagination.js"></script>
<script type="text/javascript"> 
	
	// This is a very simple demo that shows how a range of elements can
	// be paginated.
	// The elements that will be displayed are in a hidden DIV and are
	// cloned for display. The elements are static, there are no Ajax 
	// calls involved.

	/**
	 * Callback function that displays the content.
	 *
	 * Gets called every time the user clicks on a pagination link.
	 *
	 * @param {int} page_index New Page index
	 * @param {jQuery} jq the container with the pagination links as a jQuery object
	 */
	function pageselectCallback(page_index, jq){
		//var new_content = jQuery('#oculto div.elementores:eq('+page_index+')').clone();
		//$('#Searchresult').empty().append(new_content);
		///return false;
		var numElem=5;
		var content = jq;
		//$('#Searchresult').empty().append(new_content);
		//return false;
		$('#Searchresult').empty();
		//alert(page_index);
		for(var i=page_index*numElem;i<(page_index*numElem)+numElem;i++) {
            //$('#Searchresult').append(content[i]);
			//$('#Searchresult').append(content[i]);
			jQuery('#oculto div.elementores:eq('+i+')').clone().appendTo('#Searchresult');
        }
        return false;
	}
   
	/** 
	 * Initialisation function for pagination
	 */
	function initPagination() {
		// count entries inside the hidden content
		var num_entries = jQuery('#oculto div.elementores').length;
		// Create content inside pagination element
		$("#Pagination").pagination(num_entries, {
			callback: pageselectCallback,
			items_per_page:5 // Show only one item per page
		});
		pageselectCallback(0, jQuery('#oculto div.elementores'));
	 }
	

	
	
	
</script>


 	<body>
 	<?php  //require 'resize2.js';
			//require 'resizeTamFijo.js'?>
 	 	<div id="fb-root">
    </div>
    <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
    <script type="text/javascript">
      FB.init({
        appId  : '148131101921752',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : false  // parse XFBML
      });
      //FB.Canvas.setSize( );
    </script>
	<div id="cuerpo">
	 <?php require 'config_bbdd.php';?>
	 <?php require_once 'cabecera.php';?>
	 <?php require_once 'muestraPeli.php';?>
	 
		<div id="contenido">
		<?php //$user=1;
				//$_SESSION["idUser"] = $user;
				//if (!isset($_SESSION["nombreUser"]))
				//		require_once 'sacaVariablesSesion.php';
						
				/*$_SESSION["idUser"] = 1;
				$_SESSION["provinciaUser"] = 1;*/
				
		
				if (!isset($_SESSION["idUser"])){
					require_once 'vars.php';
				}
				
				
				
				if (!isset($_SESSION["provinciaUser"])){
						$_SESSION['msgError']="Debes introducir tu provincia para poder ver la cartelera.";
	 					header ("Location: configuracion.php");
				}
						?>

			<h1>Cartelera</h1>
			<p>A continuación puedes ver todas las películas de tu provincia disponibles en
			nuestra base de datos</p>
			
			<div id="Pagination"></div>
			<div id="Searchresult" style="clear: left"> 
				Cargando la cartelera
			</div> 
			
			<?php
			 //Si no se puede conectar a la BBDD 
				if (! @mysql_select_db("usersFB",$myconn)){
					echo "<p>Error al conectar a la BBDD.</p>";
					exit();
				}
				
				//TODO cambiar el 1 por el ID del usuario.
				/*$sql = "SELECT IDProvincia FROM users WHERE ID='$user'";
				$result = mysql_query($sql, $myconn);
				$row = mysql_fetch_array($result,MYSQL_BOTH);
				$idProv= $row[0];*/
				
				//Saco las películas de la provincia. Así mejor que con subconsultas.
				$sql = "SELECT p.* FROM ssii.SESION s, ssii.CINE c, ssii.PELICULA p
					WHERE s.IDCine = c.ID AND p.ID=s.IDPelicula AND c.IDProvincia=".$_SESSION["provinciaUser"]."
					GROUP BY p.ID
					ORDER BY p.Titulo;";
				$result = mysql_query($sql, $myconn);
				
				//echo "mira mama" . $_SESSION["provinciaUser"];
				//Las muestro formateadas
				echo "<div id=\"oculto\" style=\"display:none;\">";
				while($row = mysql_fetch_array($result)){
				//--------------------------------------------------
					echo "<div class=\"elementores\">";
					muestraPelicula($row, $myconn, 200, false);
					echo "</div>";//class="elementores"
					/*if ($iii==5){
					echo "<script type=\"text/javascript\">";
						echo "FB.Canvas.setSize( );";
						echo "</script>";
					}
					$iii++;*/
					 
				
					echo "\n";
				}//while
				echo "</div>";//id="oculto"
				
				
			?> 

		</div>
		<script type="text/javascript"> 
			initPagination();
		</script> 
		<?php require_once 'columnaDerecha.php';?>
		<br />
		<?php require_once 'pie.php';?>
		<script type="text/javascript"> 
			FB.Canvas.setSize( );
		</script> 
	</div>


 	</body>
</html>